#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3f;

typedef struct p
{
	int l;
	int r;
	int coin;
}p;

bool cmp(const p& p1, const p& p2)
{
	return p1.coin < p2.coin;
}

void solve()
{
	int n, c;
	cin >> n >> c;
	vector<p> a(n);
	for (int i = 0; i < n; i++) cin >> a[i].l >> a[i].r >> a[i].coin;
	sort(a.begin(), a.end(), cmp);
	for (int i = 0; i < n; i++)
	{
		if (c < a[i].coin)
		{
			if (c >= a[i].l && c <= a[i].r) c = a[i].coin;
		}
	}
	cout << c << '\n';
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}